package com.dls.admin.controller;

import com.dls.admin.model.SysUser;
import com.dls.admin.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

@Controller
public class SysUserController {

    @Autowired
    private SysUserService userService;

    /**
     * 登录控制
     *
     * @return
     */
    @RequestMapping("/index")
    public String index() {
        return "login";
    }

    /**
     * 欢迎页面
     *
     * @return
     */
    @RequestMapping("/welcome")
    public String welcome() {
        return "welcome";
    }

    /**
     * 登录校验
     *
     * @param account
     * @param password
     * @param map
     * @return
     */
    @RequestMapping(value = "/login")
    public String checkLogin(String account, String password, Map<String, Object> map) {
        SysUser user = userService.findUser(account);
        if (user != null && password.trim().equals(user.getPassword())) {
            map.put("account", account);
            //登陆成功，跳转主页
            return "index";
        } else {
            if (user == null) {
                map.put("msg", "用户名密码错误");
            }
            return "login";
        }
    }

    @RequestMapping(value = "/loginout")
    public String checkLogin() {
        return "login";
    }


}
